package com.youlei.newgraduateproject.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author youlei
 * @version 1.0
 * @Date 2021-04-12-14:19
 */

/**
 * @Author youlei
 * @Description Mybatis-plus Mybatis配置类
 * @Date 0:50 2021/4/18
 **/
@Configuration//代表其为配置类
//扫包:加载dao中的注解或xml
@MapperScan(basePackages = "com.youlei.newgraduateproject.dao")
public class MybatisConfig {
    /**
     * 新版  注册乐观锁插件 分页插件
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        //注册乐观锁插件
        //mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return mybatisPlusInterceptor;
    }

    /**
     * 新的分页插件,一缓和二缓遵循mybatis的规则,
     * 需要设置 MybatisConfiguration#useDeprecatedExecutor = false 避免缓存出现问题(该属性会在旧插件移除后一同移除)
     * 新版官方推荐
     */
    @Bean
    public ConfigurationCustomizer configurationCustomizer() {
        return configuration -> configuration.setUseDeprecatedExecutor(false);
    }



/*
    //逻辑删除组件 3.1.1开始不需要
    @Bean
    public ISqlInjector sqlInjector() {
        return new LogicSqlInjector();
    }
*/

}
